package com.xsm.adapter;

import java.util.ArrayList;

import com.xsm.activitygroup.R;
import com.xsm.object.BookObject;
import android.content.Context;
import android.graphics.Paint;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BooksAdapter extends BaseAdapter{
	ArrayList<BookObject> books;
	Context context;
	LayoutInflater infalInflater;
	ViewHolder holder;
	public BooksAdapter(Context context,ArrayList<BookObject> books){
		this.books=books;
		this.context=context;
		infalInflater=LayoutInflater.from(context);
	}
	public int getCount() {
		return books.size();
	}
	public Object getItem(int arg0) {
		return books.get(arg0);
	}
	public long getItemId(int arg0) {
		return arg0;
	}
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		holder=new ViewHolder();
		if(arg1==null){
			arg1=infalInflater.inflate(R.layout.booksitem, null);
			holder.bookName=(TextView)arg1.findViewById(R.id.bookname);
			holder.time=(TextView)arg1.findViewById(R.id.time);
			holder.price=(TextView)arg1.findViewById(R.id.price);
			holder.type=(TextView)arg1.findViewById(R.id.type);
			holder.bookType=(TextView)arg1.findViewById(R.id.booktype);
			holder.submit=(Button)arg1.findViewById(R.id.submit);
			holder.bookN=(TextView)arg1.findViewById(R.id.bookN);
			holder.goodsbg=(LinearLayout)arg1.findViewById(R.id.goodsbg);
			holder.bookicon=(LinearLayout)arg1.findViewById(R.id.bookicon);
			holder.author=(TextView)arg1.findViewById(R.id.author);
			holder.realprice=(TextView)arg1.findViewById(R.id.realprice);
			arg1.setTag(holder);
		}else {
			holder=(ViewHolder) arg1.getTag();
		}
		
		if(books.size()>0){
			String gparentid=books.get(arg0).getGparentid();
			if(gparentid.equals("1")){
				holder.bookicon.setBackgroundResource(R.drawable.bg1);	
			}else if(gparentid.equals("2")){
				holder.bookicon.setBackgroundResource(R.drawable.bg2);		
			}else {
				holder.bookicon.setBackgroundResource(R.drawable.bg3);	
			}
			
			
			holder.bookName.setText(books.get(arg0).getBookName());
			holder.time.setText(books.get(arg0).getTime());
			holder.price.setText("￥"+books.get(arg0).getPrice()+"元");		
			holder.type.setText(books.get(arg0).getPress());
			holder.bookType.setText(books.get(arg0).getBookType());
	        holder.bookN.setText(books.get(arg0).getBookName());
	        holder.author.setText("主编   "+books.get(arg0).getAuthor());
	        
	        holder.realprice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //删除线
	        if(!books.get(arg0).getRealprice().equals(""))
	        holder.realprice.setText("￥"+books.get(arg0).getRealprice()+"元");
		}
	
        
		return arg1;
	}
	
class ViewHolder{
LinearLayout goodsbg;
TextView bookN;	
Button submit;	
TextView bookType;	
TextView bookName;
TextView time;
TextView price;
TextView type;
TextView author;
TextView realprice;
LinearLayout bookicon;
}

}
